﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace BankRemoteSystem.GUI
{
    public partial class Form1 : Form
    {
        public Entities.User user = new BankRemoteSystem.Entities.User();
        public Entities.Account acc = new BankRemoteSystem.Entities.Account();
        public frmLogin newLogin = new frmLogin();
        public Form1()
        {
            InitializeComponent();            
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            //menuStrip1.Visible = false;
            
            newLogin.MdiParent = this;
            newLogin.WindowState = FormWindowState.Normal;
            
            newLogin.StartPosition = FormStartPosition.CenterScreen;
            newLogin.Show();
            
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void tlstrspmnuSavings_Click(object sender, EventArgs e)
        {            
            Form[] activeform = this.MdiChildren;
            bool flag = false;
            for (int i = 0; i < activeform.Length; i++)
            {
                if (activeform[i].Text == "Savings")
                {
                    MessageBox.Show("The window is already running.", "Bank", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                user = newLogin.us;
                frmInfo fm = new frmInfo(user, 1);
                fm.Text = "Savings";
                fm.MdiParent = this;
                fm.WindowState = FormWindowState.Maximized;
                fm.Show();
            }
         
        }

        private void tlstrspmnuChecking_Click(object sender, EventArgs e)
        {
            Form[] activeform = this.MdiChildren;
            bool flag = false;
            for (int i = 0; i < activeform.Length; i++)
            {
                if (activeform[i].Text == "Checking")
                {
                    MessageBox.Show("The window is already running.", "Bank", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                user = newLogin.us;
                frmInfo fm = new frmInfo(user, 0);
                fm.Text = "Checking";
                fm.MdiParent = this;
                fm.WindowState = FormWindowState.Maximized;
                fm.Show();
            }
        }

        private void tlstrspmnuCreditCard_Click(object sender, EventArgs e)
        {
            Form[] activeform = this.MdiChildren;
            bool flag = false;
            for (int i = 0; i < activeform.Length; i++)
            {
                if (activeform[i].Text == "Credit Card")
                {
                    MessageBox.Show("The window is already running.", "Bank", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                user = newLogin.us;
                frmInfo fm = new frmInfo(user, 2);
                fm.Text = "Credit Card";
                fm.MdiParent = this;
                fm.WindowState = FormWindowState.Maximized;
                fm.Show();
            }
        }

        private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form f in this.MdiChildren)
            {
                f.Visible = false;
            }
            newLogin.MdiParent = this;
            newLogin.WindowState = FormWindowState.Normal;

            newLogin.StartPosition = FormStartPosition.CenterScreen;
            newLogin.Show();
        }

        private void transactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            user = newLogin.us;
            BL.AccountBO bo = new BankRemoteSystem.BL.AccountBO();
            acc = bo.getAccoutbyUserID(user.UserID); 
            Transaction newT = new Transaction(acc);
            newT.MdiParent = this;
            newT.WindowState = FormWindowState.Maximized;
            newT.Show();
        }
    }
}
